local hx__yanjuexing = fk.CreateSkill{
    name = "hx__yanjuexing",

    tags = {Skill.Compulsory},
}

hx__yanjuexing:addEffect(fk.DamageCaused,{
    priority = 0.2,
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(hx__yanjuexing.name) and target and target == player
    end,
    on_use = function (self, event, target, player, data)
        data:changeDamage(data.damage)
    end,
})

hx__yanjuexing:addEffect("filter",{
    card_filter = function (self, card, player, isJudgeEvent)
        if player:hasSkill(hx__yanjuexing.name) and table.contains(player:getCardIds("h"), card.id) then
            return card.color == Card.Red
        end
    end,
    view_as = function (self, player, to_select)
        local card = Fk:cloneCard("fire__slash", to_select.suit, to_select.number)
        card.skillName = hx__yanjuexing.name
        return card
    end,
})

hx__yanjuexing:addEffect("targetmod",{
    bypass_distances = function (self, player, skill, card, to)
        if player:hasSkill(hx__yanjuexing.name) and table.contains(player:getCardIds("h"), card.id) then
            return card.skillName == hx__yanjuexing.name or card.name == "fire__slash"
        end
    end,
    bypass_times = function (self, player, skill, scope, card, to)
        if player:hasSkill(hx__yanjuexing.name) and table.contains(player:getCardIds("h"), card.id) then
            return card.skillName == hx__yanjuexing.name or card.name == "fire__slash"
        end
    end,
})

hx__yanjuexing:addEffect(fk.AfterCardsMove,{
    can_trigger = function (self, event, target, player, data)
      if not player:hasSkill(hx__yanjuexing.name) then return end
      for _, move in ipairs(data) do
        if move.from == player and move.to ~= player then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).color ~= Card.NoColor then
                return true
            end
          end
        end
      end
    end,
    on_cost = function (self, event, target, player, data)
        local red,black = 0,0
        for _, move in ipairs(data) do
        if move.from == player and move.to ~= player then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).color == Card.Red then
                red = red + 1
            elseif Fk:getCardById(info.cardId).color == Card.Black then
                black = black + 1
            end
          end
        end
        end
        if red or black then
            event:setCostData(self,{red,black})
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local red = event:getCostData(self)[1]
        local black = event:getCostData(self)[2]
        player:drawCards(red,hx__yanjuexing.name)
        player.room:changeMaxHp(player,black)
    end,
})

return hx__yanjuexing